package nl.hro.mgdd.team4.raidersofhexagoniland;

import nl.hro.mgdd.team4.raidersofhexagoniland.Scenes.SceneManager;
import nl.hro.mgdd.team4.raidersofhexagoniland.Scenes.SceneManager.GameState;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.graphics.Typeface;
import android.view.KeyEvent;

public class GameActivity extends SimpleBaseGameActivity {

	private static final int CAMERA_WIDTH = 800;
	private static final int CAMERA_HEIGHT = 480;

	public static SceneManager _manager;
	private static Camera _camera;
	protected static Font _font;

	public EngineOptions onCreateEngineOptions() {
		_camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
				new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), _camera);
	}

	@Override
	protected void onCreateResources() {
		_font = FontFactory.create(getFontManager(), getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 40);
		_font.load();
	}

	@Override
	protected Scene onCreateScene() {
		SceneManager.init(this);
		_manager = SceneManager.getManager();
		_manager.setSplashScene();
		return _manager.getCurrentScene();
	}

	public static Camera getCamera() {
		return _camera;
	}
	
	public static Font getFont(){
		return _font;
	}

	@Override
	public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) {
		if ((pKeyCode == KeyEvent.KEYCODE_MENU || pKeyCode == KeyEvent.KEYCODE_BACK)
				&& pEvent.getAction() == KeyEvent.ACTION_DOWN) {
			if (_manager.getCurrentState() == GameState.Playing) {
					SceneManager.getManager().setMainMenuScene();
				return true;
			}
				else return super.onKeyDown(pKeyCode, pEvent);
		} else
			return super.onKeyDown(pKeyCode, pEvent);
	}

}
